package com.apiit.webserviceclient;
import java.util.List;

import android.app.Activity;
import android.content.Context;
import com.apiit.webserviceclient.utils.*;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.ArrayAdapter;
import android.widget.BaseAdapter;
import android.widget.TextView;

public class Adapter extends ArrayAdapter<Book> {
	
	Context context;
	 
    public Adapter(Context context, int resourceId,List<Book> items) {
        super(context, resourceId, items);
        this.context = context;
    }
 
    /*private view holder class*/
    private class ViewHolder {

        TextView title;
        TextView titleCode;
        TextView callNo;
        TextView author;
        TextView type;
        TextView category;
    }
 
    public View getView(int position, View convertView, ViewGroup parent) {
        ViewHolder holder = null;
        Book rowItem = getItem(position);
 
        LayoutInflater mInflater = (LayoutInflater) context.getSystemService(Activity.LAYOUT_INFLATER_SERVICE);
        if (convertView == null) {
            convertView = mInflater.inflate(R.layout.activity_list, null);
            holder = new ViewHolder();
            
            holder.title = (TextView) convertView.findViewById(R.id.listtitle);
            holder.titleCode = (TextView) convertView.findViewById(R.id.listtitlecode);
            holder.callNo = (TextView) convertView.findViewById(R.id.listcallno);
            holder.author = (TextView) convertView.findViewById(R.id.listauthor);
            holder.type = (TextView) convertView.findViewById(R.id.listtype);
            holder.category = (TextView) convertView.findViewById(R.id.listcategory);
            convertView.setTag(holder);
        } else
            holder = (ViewHolder) convertView.getTag();
 
        holder.title.setText(rowItem.getTitle1());
        holder.titleCode.setText(rowItem.getTitleCode());
        holder.callNo.setText(rowItem.getCallNo());
        holder.author.setText(rowItem.getAuthor());
        holder.type.setText(rowItem.getType());
        holder.category.setText(rowItem.getCategory());
 
 
        return convertView;
    }
}
